<template>
  <div>
    <!-- 顶部 -->
    <div class="header">
      <img
      @click="clickHandler"
        src="https://imagev2.xmcdn.com/storages/72b6-audiofreehighqps/30/CE/GMCoOR8H3gffAAAQWAIAHhDF.png!magick=webp"
      />
      <div class="open">打开</div>
    </div>
    <!-- 图片介绍 -->
    <div class="bg">
      <div class="bg-blur"></div>
      <div class="bg-content">
        <div class="bg_left">
          <img
            :src="'https://imagev2.xmcdn.com/'+albumDetailInfo?.albumInfo.cover"
          />
          <div class="info-bar">
            <van-icon name="audio" />
            <p class="count">9250.77万</p>
          </div>
        </div>
        <div class="bg_right">
          <div class="title">{{ albumDetailInfo?.albumInfo.title }}</div>
          <div class="nameWrapper">
            <img
              src="https://imagev2.xmcdn.com/group83/M03/5C/BB/wKg5I179zNfxD-EaAADQ6CFH3IQ282.jpg!op_type=5&device_type=ios&name=web_meduim&upload_type=cover&magick=webp"
            />
            <div class="name">麦疯的思远</div>
          </div>
          <div class="subscribeWrapper">已订阅{{ formatNumber(albumDetailInfo?.statCountInfo.subscribeCount) }}万人</div>
        </div>
      </div>
    </div>
    <!-- 内容介绍 -->
    <div class="rich">
<div class="pdd">
  <div>
  <div :class="{
    ssr:!isShowAll
  }"  v-html="albumRichInfo?.richIntro"></div>
  <div class="mask" v-show="!isShowAll"></div>
<pullDown v-model="isShowAll"></pullDown>
</div>
<!-- 节目单 -->
<program :id="+route.params.id"></program>
<!-- 评论 -->
<comment :id="+route.params.id"></comment>
    <!-- 主播信息 -->
<anchor :userInfo="userInfo" :countInfo="countInfo" :anchorAlbum="anchorAlbum!"></anchor>
<!-- 相似专辑 -->
<!-- <like></like> -->
<!-- 猜你喜欢 -->
<Guess></Guess>
</div>
<bottom></bottom>
    </div>
</div>
</template>

<script setup lang="ts">
import { formatNumber } from '../../utils/formatNumber';
import anchor from './components/anchor.vue'
import like from './components/like.vue';
import Guess from './components/Guess.vue';
import program from './components/program.vue';
import comment from './components/comment.vue';
import { onMounted, ref, watch } from 'vue';
import bottom from '../search/components/anchor/bottom.vue';
import pullDown from './components/pull-down.vue';
import {reqDetailPage,reqUserCountInfo,reqAnchorAlbumInfo} from '../../api/detail/index'
import {useRoute,useRouter} from 'vue-router'
import type {albumDetailInfoType,albumRichInfoType,albumBriefDetailInfoItem,userINfoType} from '../../api/detail/type'
const albumDetailInfo=ref<albumDetailInfoType>();
const albumRichInfo=ref<albumRichInfoType>();
const anchorAlbum=ref<albumBriefDetailInfoItem[]>();
const userInfo=ref<userINfoType>();
const countInfo=ref();
const router=useRouter()
const clickHandler=()=>{
  router.push('/home')
}

let isShowAll=ref<boolean>(false);

//获取路由对象
let route=useRoute();
onMounted(()=>{
  
  getHeaderData(+route.params.id);
  getUserCountInfo(+route.query.anchorId!||89413136);
  getAnchorAlbumInfo(+route.query.anchorId!||89413136)
});
watch(()=>route.query.anchorId,()=>{
  console.log('333');
  
  getHeaderData(+route.params.id);
  getUserCountInfo(+route.query.anchorId!||89413136);
  getAnchorAlbumInfo(+route.query.anchorId!||89413136)
})


//请求头部数据的功能函数

const getHeaderData=async(id:number)=>{
  try {
    let res=await reqDetailPage(id);
    if(res.ret==0){
      albumDetailInfo.value=res.data.albumDetailInfo;
      albumRichInfo.value=res.data.albumRichInfo
    }
  } catch (error) {
    console.log(error);
    
  }
};

//请求获得主播信息

const getUserCountInfo=async(id:number)=>{
  try {
    let res=await reqUserCountInfo(id);
    if(res.ret==0){
      userInfo.value=res.data.userInfo;
      countInfo.value=res.data.statCountInfo.followerCount;
      
    }
  } catch (error) {
    console.log(error);
    
  }
};


//请求主播作品函数

const getAnchorAlbumInfo=async(id:number)=>{
  try {
    let res=await reqAnchorAlbumInfo(id);
    if(res.ret==0){
      anchorAlbum.value=res.data.albumBriefDetailInfos;
    }
  } catch (error) {
    console.log(error);
    
  }
}



</script>

<style lang="less" scoped>
.mask{
  position: absolute;
  top:20px;
  left: 0;
  width: 375px;
  height: 100px;
  background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,rgba(255,255,255,0)),color-stop(34%,rgba(255,255,255,0.8)),color-stop(66%,rgba(255,255,255,0.95)),to(#fff));
}
.ssr{
  height: 100px;
  overflow: hidden;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 40px;
  padding: 10px 8px;
  background: rgba(34, 35, 37, 0.8);
  img {
    width: 102px;
    height: 36px;
  }
  .open {
    width: 60px;
    height: 30px;
    background: #f86442;
    border: 1px solid #f86442;
    color: #fff;
    border-radius: 100px;
    text-align: center;
    line-height: 30px;
    cursor: pointer;
    padding: 3px 0;
    font-size: 15px;
  }
}
.bg {
  position: relative;
  height: 150px;
  // margin-top: 40px;
  width: 100%;
  overflow: hidden;
  .bg-blur {
    background-image: url(https://imagev2.xmcdn.com/group87/M09/6B/8C/wKg5J19fJ43hQk-FAAHkyMn-doo255.jpg!op_type=3&columns=144&rows=144&magick=webp);
    transform: scale(2);
    background-position: left;
    filter: blur(15px);
   max-width: 100%;
    height: 80px;
    &::after {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.3);
    }
  }
  .bg-content {
    padding: 20px 20px;
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    .bg_left {
      width: 95px;
      height: 95px;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
      .info-bar {
        background-image: linear-gradient(
          180deg,
          rgba(3, 3, 3, 0) 9%,
          rgba(0, 0, 0, 0.58) 100%
        );
        width: 100%;
        height: 28px;
        line-height: 34px;
        border-radius: 0 0 4px 4px;
        display: flex;
        align-items: center;
        position: absolute;
        left: 0;
        bottom: 0;
        font-size: 16px;
        color: #fff;
        .count {
          font-size: 12px;
          margin-left: 5px;
        }
      }
    }
    .bg_right {
      width: 215px;
      height: 118px;
      margin-left: 15px;
      .title {
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 17px;
        color: #fff;
        line-height: 23px;
      }
      .nameWrapper{
        padding: 10px 0;
        display: flex;
        align-items: center;
    font-size: 12px;
    color: rgba(255,255,255,.81);
        img{
          width: 20px;
          height: 20px;
          border-radius: 50%;
          margin-right: 6px;
        }
      }
      .subscribeWrapper{
        border-top: 1px solid #ccc;
        padding-top: 5px;
        margin: 0 auto 10px 0;
        font-size: 12px;
        color: #fff;
      }
    }
  }
}
.pdd{
  padding: 15px 15px 0;
}
.rich{
  box-sizing: border-box;
  width: 375px;
  color: rgba(0, 0, 0, 0.8) !important;
  font-size: 14px !important;
  line-height: 21px !important;
  position: absolute;
  left: 0;
  top: 230px;
  border-top: 2px solid #fff;
  margin-top: 0px;
  background-color: #fff;
  img{
    width: 100% !important;
  }
  p{
    font-size: 14px;
    line-height: 21px;
    // color: #fff;
    margin: 0;
  } 
  .flag{
    background-color: #FC5832;
    display: inline-block;
    margin: 10px 0;
    padding: 5px;
    font-size: 14px;
  }
}
</style>
